home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10781 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: status.gen.nz!usenet
  2. From: dteviot@iconz.co.nz (David Teviotdale)
  3. Newsgroups: comp.lang.c++
  4. Subject: Memory leak in Borland C++ Tutorial?
  5. Date: 10 Mar 1996 05:42:02 GMT
  6. Organization: Internet Company of New Zealand
  7. Message-ID: <4htq3a$lon@status.gen.nz>
  8. NNTP-Posting-Host: dteviot.internet.co.nz
  9. X-Newsreader: WinVN 0.93.14
  10.  
  11. I have recently purchased Borland C++ 4.51, and am working my
  12. way through the ObjectWindows Tutorial book.  However, I am 
  13. very puzzled, as in many places, the code shown looks like 
  14. it will cause memory leaks. For example:
  15.  
  16. on page 5 is the line:
  17. SetMainWindow( new TFrameWindow( 0, "Sample ObjectWindows Program" ) )
  18.  
  19. on page 41 the code:
  20. if ( new TFileSaveDialog( this, "FileData()->Execute() == IDOK ) )
  21.    SaveFile();
  22.  
  23. And there's even worse stuff elsewhere.
  24.  
  25. What is going on?  Currently my theories are:
  26. 1) The code is correct, the memory is only allocated once, and we
  27.    rely on Windows to cleanup the allocated memory when the program
  28.    ends.  ( This might apply to the code on page 5, but I can't see
  29.    how it applies to the code on page 41. )
  30. 2) The compiler ( or run time memory manager ) is VERY sophisticated,
  31.    and can detect that in cases like above we only want the memory
  32.    temporarily, and will automatically free it when we are done.
  33. 3) The code shown has been delibertely simplified to emphasise the
  34.    basic principles of ObjectWindows, with the fine details for
  35.    getting it to work in non-toy programs removed.
  36.  
  37.